package com.findyou.cookie;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: CookieController
 * @Author 贾金博
 * @Package com.findyou.cookie
 * @Date 2024/3/3 16:22
 * @description: 接收cookie
 */

@RestController
@RequestMapping("/cookie")
public class CookieController {


    @RequestMapping("data")
    @ResponseBody
    /**
     * 看看有没有cookie的名字是 = cookieName的 有的话 获取他的value值
     */
    public String data(@CookieValue(value = "cookieName") String value)  {
        System.out.println("value = " + value);
        return "value = " + value;
    }

    @GetMapping("save")
    public String save(HttpServletResponse response) {
        Cookie cookie = new Cookie("cookieName", "root");
        response.addCookie(cookie);
        return "ok";
    }

}
